const express = require('express');
const app = express();
const path = require('path')
var data = require('./data/city.json')
app.use(express.static(path.join(__dirname,'./public')))
app.get('/province',(req,res)=>{
    var provinceData = Object.keys(data)
    res.send(provinceData)
})
app.get('/city/:provinceName',(req,res)=>{
    var key = req.params.provinceName
    var cityObj = data[key]
    var cityData = Object.keys(cityObj)
    res.send(cityData)
})
app.get('/area/:cityName',(req,res)=>{
    var key = req.params.cityName 
    for(var i in data){
        for(var j in data[i]){
            if(j == key){
                res.send(data[i][j])
                return 
            }
        }
    }
    res.status(500).send('服务器出错了')
})
app.listen(3000);
console.log('正在监听端口3000,http://127.0.0.1:3000')